<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>商品导入</title>
</head>
<style>
      table,table tr th, table tr td { border:1px solid #0094ff; }
</style>
<body>
<div style="float: left">
    <table>
        <tr>
            <th>id</th>
            <th>商品编号</th>
            <th>商品名称</th>
            <th>型号</th>
            <th>产地</th>
            <th>规格</th>
            <th>本期数量</th>
            <th>成本均价</th>
            <th>本期金额</th>
            <th>操作</th>
        </tr>
        {volist name="list" id="vo"}
        <tr>
            <td class="gid gid{$vo[0]}">{$vo[0]}</td>
            <td >{$vo[1]}</td>
            <td class="title">{$vo[2]}</td>
            <td>{$vo[3]}</td>
            <td class="brand">{$vo[4]}</td>
            <td>{$vo[5]}</td>
            <td class="num">{$vo[6]}</td>
            <td>{$vo[7]}</td>
            <td class="balance">{$vo[8]}</td>
            <td>
                <button class="seachgoods">搜索商品库</button>
<!--                <button class="getcate">自动搜索分类</button>-->
<!--                <button class="">自动匹配供应商</button>-->
<!--                <button>添加入库</button>-->
            </td>
        </tr>
        {/volist}
    </table>
</div>
<div style="position: fixed;background: #1a59b7;color: #ffffff;right: 10px;">
    <select name="" id="" class="house">
        {volist name="hlist" id="vo"}
            <option value="{$vo.id}">{$vo.name}</option>
        {/volist}
    </select>
</div>

    <div style="position: fixed;background: #1a59b7;color: #ffffff;right: 140px;">
        <table>
            <tr>
                <th>id</th>
                <th>商品名称</th>
                <th>规格</th>
                <th>操作</th>
            </tr>
            <tbody class="showgoods">

            </tbody>

        </table>
    </div>

</body>
</html>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.js"></script>
<script src="https://erp.gotobby.com/assets/libs/fastadmin-layer/src/layer.js"></script>
<script>
    var balance = 0
    var num = 0
    var gid = 0
    $('.seachgoods').click(function () {
        var title = $(this).parents('tr').find('.title').html();
        var brand = $(this).parents('tr').find('.brand').html();
        balance = $(this).parents('tr').find('.balance').html();
        gid = $(this).parents('tr').find('.gid').html();
        num = $(this).parents('tr').find('.num').html();
        $.post('/index/index/getgoods',{title:title,brand:brand},function (res) {
            $('.showgoods').find('tr').remove();
            if(res.total >0){
                str = ''
                for (var i=0;i<res.total;i++){
                    str+='<tr >\n' +
                        '                    <td class="goods_id">'+res.data[i]['id']+'</td>\n' +
                        '                    <td>'+res.data[i]['title']+'</td>\n' +
                        '                    <td>'+res.data[i]['specs']+'</td>\n' +
                        '                    <td>\n' +
                        '                        <button class="addstock">添加库存</button>\n' +
                        '                    </td>\n' +
                        '                </tr>'
                }
                $('.showgoods').append(str)
            }else{
                // $('.showgoods').find('tr').remove();
            }
        })
    })
    $('.showgoods').on('click','.addstock',function () {
        var goods_id = $(this).parents('tr').find('.goods_id').html()
        var msg = '确定给商品ID为'+goods_id+'的商品添加金额为:'+balance+'数量为:'+num
        var house_id = $('.house').val()
        console.log(house_id)
        if(confirm(msg)){
            //点击确定后操作
            $.post('/index/index/setstock',{goods_id:goods_id,balance:balance,num:num,house_id:house_id},function (res) {
                if(res.code >0){
                    // layer.msg('成功')
                    $('.gid'+gid).parents('tr').find('.seachgoods').attr('style','display:none')
                }
            })
        }
    })
    // $('.catelist').find('option').each(function () {
    //     console.log($(this).html())
    //     console.log($(this).val())
    // })
    // $('table').on('click','.getcate',function () {
    //     var goods_name = $(this).parents('tr').find('.goods_name').html()
    //     var brand_name = $(this).parents('tr').find('.brand_name').html()
    //     var that = $(this)
    //     that.find('.catelist').find('option').each(function () {
    //         console.log($(this).html())
    //         console.log($(this).val())
    //     })
    //     $.get('http://erp8.zteam.top/Home/Goods/get_category',{goods_name:goods_name,brand_name:brand_name},function (res) {
    //         console.log(res)
    //         // if(res.code == 1){
    //             that.find('.catelist').find('option').each(function () {
    //                 console.log($(this).html())
    //             })
    //         // }
    //     })
    // })
</script>